function [val] = rice_information_ExpectVal(A,compmode)
% [val] = rice_information_ExpectVal(A)
% Computes the expected information value of the rice distribution with
% parameters A and sigma = 1. This is used for CRLB computations involving
% rice distributions. For normal distributions this value == 1/sigma^2,
% but for rice distributions no analytical solution can be found.
% This function uses a table to quicly evaluate the requested values. This
% table is created on the first call, so be patient please.
% 
% Created by Dirk Poot, University of Antwerp.
% 12-3-2008


% compmode = 1  : compute each value (error ~ eps), extremely slow
% compmode = 2  : compute with accurate table (error ~ 1e-12)
% compmode = 3  : Compute with very fast very accurate table (error ~ eps( result_val ), more accurate than compmode==1 !!)
% compmode = 4  : compute with very slightly less accurate table (error ~ 2 * eps, evaluates very slightly faster)
% compmode = 5  : compute with much less accurate table (error ~ 1e-9, evaluates slightly faster)

persistent Etable;
if nargin<2
    compmode = 3;
end;
if compmode ==3  
    if nargout<=1
%%        
    limits = [0,11984,29455,45600,61043,76050,90770,105301,119716, ...
        134073,148421,162801,177262,191831,206571,221519,236726,252254, ...
        268181,284612,301644,319648,339122,362464,385006,405156,424588, ...
        443716,462739,481776,500910,520203,539701,559458,579509,599892, ...
        620626,641762,663362,685446,708026,731174,754979,779423,804658, ...
        830720,857705,885729,914864,945382,977582,1012136,1049703,1094961, ...
        1141534,1182932,1222773,1261956,1300888,1339801,1378847,1418133, ...
        1457740,1497732,1538162,1579075,1620509,1662501,1705044,1748248, ...
        1792103,1836639,1881836,1927825,1974589,2022164,2070588,2119838, ...
        2170091,2221335,2273634,2327059,2381601,2437441,2494806,2553744, ...
        2614296,2668749,2746657,2844531,2926702,3006842,3087519,3170107, ...
        3255720,3345530,3441020,3544414,3659992,3800483,3957855,4104357, ...
        4254942,4415864,4594181,4803511,5117682,5405386,5725870,6127612, ...
        6822646,7685015,9253009,13279768,inf]'*(1/1048576); 
    CutoffLimit = (326787/131072);

    tbl = [0,0,0.99999999999986077E0,0,(-0.999999980813366552E0),0,0.124960825865620829E1;
        0.130601165585066031E-3,0.228516962222327425E-1,0.999216610355413854E0,(-0.456780077642292068E-1),(-0.997557619906881925E0),0.859155554702885696E-1,0.122802613725552825E1;
        0.788452871679599386E-3,0.560924229749207033E-1,0.995277197566286345E0,(-0.111809688717196673E0),(-0.985297931636477755E0),0.208804858503027070E0,0.117942649476833831E1;
        0.188759882006220286E-2,0.866472906228597767E-1,0.988719681568243316E0,(-0.171911382018512321E0),(-0.965043488751447449E0),0.317855479735749716E0,0.111042832390091891E1;
        0.337756572974604625E-2,0.115646096213308237E0,0.979879177317472265E0,(-0.228002069773135135E0),(-0.938041262871325443E0),0.416050638476340528E0,0.102503443514020929E1;
        0.523266700667487416E-2,0.143542735671509146E0,0.968949845907862205E0,(-0.280789985995963173E0),(-0.905138282087768293E0),0.504125575396693586E0,0.926635572694700631E0;
        0.743786947241597212E-2,0.170571218863626815E0,0.956068828063170213E0,(-0.330570881416112231E0),(-0.867034058957453080E0),0.582214112201375522E0,0.818348290293511403E0;
        0.998431021887866613E-2,0.196869751410370296E0,0.941342747987134778E0,(-0.377470123555649571E0),(-0.824356133721050497E0),0.650283274577604957E0,0.703092182827666727E0;
        0.128676118071791962E-1,0.222528975975859547E0,0.924857779590409114E0,(-0.421535051113389244E0),(-0.777686159917382120E0),0.708290215004888495E0,0.583601973737958718E0;
        0.160867292021812902E-1,0.247610168704434335E0,0.906686668869974278E0,(-0.462769283744649655E0),(-0.727577122129400748E0),0.756236206777432983E0,0.462423505704749321E0;
        0.196434092744592304E-1,0.272155875122492419E0,0.886892267383767686E0,(-0.501152343981832281E0),(-0.674560484528578003E0),0.794192635440474164E0,0.341908901935962750E0;
        0.235411916971691111E-1,0.296191694656511679E0,0.865533583037357205E0,(-0.536644324285045482E0),(-0.619159668404912250E0),0.822309301483411273E0,0.224154424091182199E0;
        0.277891860296932863E-1,0.319752441476872426E0,0.842645989384688279E0,(-0.569224115791492411E0),(-0.561837791601291143E0),0.840830270127082941E0,0.111063085643624601E0;
        0.323929741278293790E-1,0.342832495685585418E0,0.818291304284726982E0,(-0.598819853252051659E0),(-0.503122911788302455E0),0.850057580793867567E0,0.423973220626916741E-2;
        0.373722400411010319E-1,0.365477786995805584E0,0.792465286783342498E0,(-0.625429789298964046E0),(-0.443381991461332431E0),0.850376025966553695E0,(-0.949696056002341021E-1);
        0.427415323634920136E-1,0.387685540216743660E0,0.765201751264110884E0,(-0.648989729366284292E0),(-0.383076215415968598E0),0.842208150609352988E0,(-0.185386950344201830E0);
        0.485228954753287102E-1,0.409466274608384829E0,0.736507928282078950E0,(-0.669451970952592022E0),(-0.322606589225094582E0),0.826027131362110707E0,(-0.266107196432636444E0);
        0.547458646511904578E-1,0.430835239835375355E0,0.706369033311800489E0,(-0.686767288179687614E0),(-0.262334989955540682E0),0.802329426140235946E0,(-0.336451897043908662E0);
        0.614504417921880319E-1,0.451814760246408778E0,0.674739462326596611E0,(-0.700878413201639064E0),(-0.202578987720646757E0),0.771609804374477445E0,(-0.395943392645298408E0);
        0.686932685537253120E-1,0.472441680212052433E0,0.641522419770336463E0,(-0.711711755450821489E0),(-0.143593841130048846E0),0.734320086701367833E0,(-0.444201435202984213E0);
        0.765333262870708497E-1,0.492716622011249510E0,0.606645153319515225E0,(-0.719142008726073962E0),(-0.857236392830253260E-1),0.690968223366283241E0,(-0.481144109091553072E0);
        0.851684440248077859E-1,0.512911294232072692E0,0.569484967671938632E0,(-0.723041180058064028E0),(-0.285393689691365530E-1),0.641331238605642447E0,(-0.506625290487406876E0);
        0.948859471298010996E-1,0.533315560148143553E0,0.529181438537073401E0,(-0.723014166913127074E0),0.283881858014068072E-1,0.584793210318025336E0,(-0.520096019607980076E0);
        0.107012170285689875E0,0.555802534743375111E0,0.481044105320033071E0,(-0.717703303113231109E0),0.896120170930467361E-1,0.515174491425393375E0,(-0.519030488105451113E0);
        0.119175867656329621E0,0.575494276464370536E0,0.435055144848211620E0,(-0.707719731557529313E0),0.141394038141070058E0,0.448168965072518988E0,(-0.506416038930820489E0);
        0.130390528425856835E0,0.591435064225384258E0,0.394599423794719675E0,(-0.695268214254040502E0),0.181656659983049936E0,0.389738711097939214E0,(-0.486938631042096685E0);
        0.141481998012325618E0,0.605348863977069105E0,0.356343969143123719E0,(-0.680526027999154290E0),0.215268733341772120E0,0.335564986533805531E0,(-0.462562033340109635E0);
        0.152639173520350176E0,0.617675672309447025E0,0.319551148616155498E0,(-0.663757912875504780E0),0.243575175669885498E0,0.284913740431902951E0,(-0.434681349712712705E0);
        0.163946124341413151E0,0.628620696871322467E0,0.283923268015447222E0,(-0.645196590056549349E0),0.267282725066530770E0,0.237581188373852930E0,(-0.404396337527349380E0);
        0.175448546533782035E0,0.638298543307109196E0,0.249324594776403174E0,(-0.625051728254277446E0),0.286859754942442342E0,0.193517735207951171E0,(-0.372611050897191784E0);
        0.187175219065288740E0,0.646780391109652625E0,0.215691746354439130E0,(-0.603514630056540870E0),0.302665109001178634E0,0.152714156079314230E0,(-0.340080435556605859E0);
        0.199144780213754323E0,0.654112215988591880E0,0.183002816004887537E0,(-0.580764779960581085E0),0.314997770470873984E0,0.115166724975138364E0,(-0.307441237879042608E0);
        0.211367407788440359E0,0.660323738551916295E0,0.151265646125781464E0,(-0.556976899665028848E0),0.324121293031790208E0,0.808646748115583860E-1,(-0.275215555778466822E0);
        0.223859074683614333E0,0.665439475544676126E0,0.120477687856843834E0,(-0.532298599098654126E0),0.330284475198716045E0,0.497531238790752944E-1,(-0.243832863271895415E0);
        0.236624066389371440E0,0.669472407198577893E0,0.906692610946835732E-1,(-0.506887810276539294E0),0.333714532315705737E0,0.217815934552468251E-1,(-0.213647824459777046E0);
        0.249668354069063765E0,0.672432611937383081E0,0.618672108904720423E-1,(-0.480888926450008394E0),0.334630952430593182E0,(-0.312990385021651124E-2),(-0.184949079153606831E0);
        0.262985211840855461E0,0.674325545959756556E0,0.341250230250480574E-1,(-0.454462483869184456E0),0.333246890295096425E0,(-0.250645090667763554E-1),(-0.157947167286362255E0);
        0.276587695666549826E0,0.675158202566065537E0,0.745335628586516237E-2,(-0.427721347678676685E0),0.329767969351443433E0,(-0.441582763488709223E-1),(-0.132769690474839382E0);
        0.290495009271689180E0,0.674932268754156243E0,(-0.181436364592316656E-1),(-0.400759893615557770E0),0.324384177744195074E0,(-0.605577390154584160E-1),(-0.109518533824307141E0);
        0.304697991585753460E0,0.673646796461859109E0,(-0.426074516226744467E-1),(-0.373721619874521220E0),0.317287511775205866E0,(-0.743850608500246764E-1),(-0.882762706737258244E-1);
        0.319180857322606464E0,0.671304475106916740E0,(-0.658755103344986097E-1),(-0.346754347525134243E0),0.308673022418009214E0,(-0.857787499222832271E-1),(-0.690578517392711404E-1);
        0.333964581006127158E0,0.667902208320048257E0,(-0.879469084174626586E-1),(-0.319930601317889971E0),0.298708190345434498E0,(-0.949141640252800226E-1),(-0.518212604059631899E-1);
        0.349078450341297072E0,0.663428213190171925E0,(-0.108823913538402011E0),(-0.293306553324232200E0),0.287541333097666515E0,(-0.101959477152804040E0),(-0.365394402462152701E-1);
        0.364481263613443021E0,0.657890733410869185E0,(-0.128411786076160735E0),(-0.267057679181161516E0),0.275366320370527831E0,(-0.107058300988620429E0),(-0.231438405844648246E-1);
        0.380236039958075508E0,0.651261180391582696E0,(-0.146750926720744370E0),(-0.241176348898105539E0),0.262289444718007407E0,(-0.110387469055719229E0),(-0.115422900039689918E-1);
        0.396328655206718828E0,0.643535226104831704E0,(-0.163778827700628634E0),(-0.215785355775067054E0),0.248470199033342338E0,(-0.112096204050279941E0),(-0.164960264297446651E-2);
        0.412777932437244415E0,0.634693521417403050E0,(-0.179470239682193268E0),(-0.190950889400417464E0),0.234035224603295625E0,(-0.112338590056933140E0),0.664148367131111883E-2;
        0.429608888028294383E0,0.624708975744011729E0,(-0.193798579991746558E0),(-0.166731664280087683E0),0.219099426303659735E0,(-0.111260936456005179E0),0.134362562053810448E-1;
        0.446813550341466771E0,0.613571779163667144E0,(-0.206705495945453644E0),(-0.143233884534899328E0),0.203802027426064687E0,(-0.109009308796933798E0),0.188565873225224099E-1;
        0.464492607857824107E0,0.601195496451487709E0,(-0.218202512930292352E0),(-0.120421949569423925E0),0.188181935992978958E0,(-0.105705152006241478E0),0.230280021747596563E-1;
        0.482745219554399322E0,0.587474891693542525E0,(-0.228261946457345009E0),(-0.982904124712687767E-1),0.172280397621181620E0,(-0.101451745470184514E0),0.260689323984805185E-1;
        0.501853242101685746E0,0.572134802052704613E0,(-0.236892264668331072E0),(-0.766646307901884639E-1),0.155991383975086034E0,(-0.962857240583684245E-1),0.280692884393982725E-1;
        0.522043596878810788E0,0.554893375027269621E0,(-0.243974428938662481E0),(-0.555200741645939997E-1),0.139285234151955950E0,(-0.902403105597240497E-1),0.291081807760656084E-1;
        0.545535072024861232E0,0.533565794550033289E0,(-0.249677591428845164E0),(-0.331073670041364872E-1),0.120624161180661459E0,(-0.826810895408380431E-1),0.291235610558356171E-1;
        0.568738656609706573E0,0.511231459006533486E0,(-0.252732018215547871E0),(-0.132570900055144787E-1),0.103123170880896096E0,(-0.749125867096791230E-1),0.283646289239828518E-1;
        0.588527679199116973E0,0.491238132072102734E0,(-0.253382841482048173E0),0.189546547538468335E-2,0.889969228978452526E-1,(-0.681895150061122292E-1),0.272171498184086650E-1;
        0.606826927352854813E0,0.472010436506969764E0,(-0.252432457231043406E0),0.144667821203149808E-1,0.766300560333191706E-1,(-0.619823190142331433E-1),0.258391859934191307E-1;
        0.624113343479317290E0,0.453220737991735154E0,(-0.250200250755219331E0),0.250822478416077858E-1,0.655885813855186213E-1,(-0.561875461436439882E-1),0.243265428119915454E-1;
        0.640597224338729704E0,0.434758277359381687E0,(-0.246892029081883418E0),0.340734014806595918E-1,0.556587784835814921E-1,(-0.507675496779425635E-1),0.227446021437862351E-1;
        0.656393076461218374E0,0.416585470420152940E0,(-0.242663991041775789E0),0.416595535311933673E-1,0.467065489847070189E-1,(-0.457029337145234700E-1),0.211398038355454915E-1;
        0.671571297449057762E0,0.398695743541894724E0,(-0.237644546505677996E0),0.480045423974922189E-1,0.386349151774397458E-1,(-0.409799249965269367E-1),0.195455927080981745E-1;
        0.686177866764145133E0,0.381098423991011618E0,(-0.231944507109340924E0),0.532398543182581760E-1,0.313676113936794277E-1,(-0.365865294446199254E-1),0.179860386727609327E-1;
        0.700244790835286323E0,0.363810600808102882E0,(-0.225662198993655242E0),0.574765383590991801E-1,0.248407315888749369E-1,(-0.325108797866554772E-1),0.164782219508215290E-1;
        0.713795276504513022E0,0.346853378901043950E0,(-0.218886558847082043E0),0.608115522307752680E-1,0.189985638732528296E-1,(-0.287407948895024740E-1),0.150339374072631419E-1;
        0.726847038939398661E0,0.330249399706379376E0,(-0.211698927515023386E0),0.633316277916663237E-1,0.137910786182697919E-1,(-0.252636383960259750E-1),0.136609530685541225E-1;
        0.739414109022230343E0,0.314021634469729533E0,(-0.204174328739101750E0),0.651156318548239394E-1,0.917251937241335817E-2,(-0.220664281835212388E-1),0.123639914029920860E-1;
        0.751507770161857267E0,0.298192940756833919E0,(-0.196382516486460148E0),0.662361349762068330E-1,0.510056499876316439E-2,(-0.191360268459915675E-1),0.111454126857687613E-1;
        0.763138730141601307E0,0.282783747744804092E0,(-0.188387682586134071E0),0.667606022873432835E-1,0.153527223922270604E-2,(-0.164590302587425583E-1),0.100063097716142218E-1;
        0.774306235388392041E0,0.267827032685372896E0,(-0.180257238271724956E0),0.667521928280957490E-1,(-0.155821162884201867E-2),(-0.140240839390323005E-1),0.894538614165751854E-2;
        0.785040040183723511E0,0.253312252521967465E0,(-0.172031452280738806E0),0.662698178198276073E-1,(-0.422114999349838019E-2),(-0.118136221768383446E-1),0.796055450243986111E-2;
        0.795338333646764105E0,0.239268723256170744E0,(-0.163769146576159025E0),0.653686505368992533E-1,(-0.648422594723875939E-2),(-0.981695988107545762E-2),0.704997841904719276E-2;
        0.805210311671252693E0,0.225708864593803441E0,(-0.155517330638984699E0),0.641007472446749896E-1,(-0.837966954224443252E-2),(-0.802136003368078932E-2),0.621128229493633922E-2;
        0.814655259562803716E0,0.212656728571797897E0,(-0.147327998205120982E0),0.625169044488393455E-1,(-0.993666880393686160E-2),(-0.641586949066046649E-2),0.544082534145495650E-2;
        0.823703911354126464E0,0.200090850653144566E0,(-0.139222094182094632E0),0.606594400853193467E-1,(-0.111879285814234218E-1),(-0.498500277596997878E-2),0.473496382764179483E-2;
        0.832355918222777239E0,0.188030783237333559E0,(-0.131243947420762715E0),0.585728705822730916E-1,(-0.121594826824758484E-1),(-0.371885710759315263E-2),0.409077498486211623E-2;
        0.840622321759942348E0,0.176478536120169379E0,(-0.123424806120000061E0),0.562972035949553456E-1,(-0.128779606116760990E-1),(-0.260607373874907433E-2),0.350489140754282164E-2;
        0.848514490952683767E0,0.165433902179251291E0,(-0.115792382575151011E0),0.538696741870016499E-1,(-0.133686699292750563E-1),(-0.163576872878099662E-2),0.297432949721135946E-2;
        0.856034740648276923E0,0.154907661286239916E0,(-0.108380284169379548E0),0.513281286404787480E-1,(-0.136554055905762017E-1),(-0.798299588417990228E-3),0.249544646415313674E-2;
        0.863215338911235922E0,0.144867054464909886E0,(-0.101189447405686488E0),0.486975457120638226E-1,(-0.137616698533674212E-1),(-0.814755526080551460E-4),0.206485347437130458E-2;
        0.870058940420505915E0,0.135319267560804979E0,(-0.942470068895380100E-1),0.460102836311738102E-1,(-0.137084859122176415E-1),0.523272067939911739E-3,0.167984897405887977E-2;
        0.876579324765423970E0,0.126254486408160301E0,(-0.875663560945546481E-1),0.432925595522942922E-1,(-0.135161240853524120E-1),0.102529893441059398E-2,0.133751808462589216E-2;
        0.882790318271407728E0,0.117661503003936446E0,(-0.811581103262635295E-1),0.405681243170069162E-1,(-0.132035982586326472E-1),0.143349341814913565E-2,0.103531300511251961E-2;
        0.888696549612980429E0,0.109540479865239332E0,(-0.750398306354329163E-1),0.378626658546128785E-1,(-0.127894505197824004E-1),0.175598479570366609E-2,0.770480382627054015E-3;
        0.894322738292587115E0,0.101862732540878500E0,(-0.692057821722178709E-1),0.351904754783656219E-1,(-0.122897455600233084E-1),0.200160507305058082E-2,0.540005005465727770E-3;
        0.899693922396531392E0,0.945985864695205935E-1,(-0.636475735873553130E-1),0.325627835372200501E-1,(-0.117185600935772383E-1),0.217829150951291763E-2,0.341509352896528085E-3;
        0.904815672126714511E0,0.877440374679830378E-1,(-0.583749558514274518E-1),0.299981236843380941E-1,(-0.110907049757899510E-1),0.229289453094473669E-2,0.173026200944974802E-3;
        0.100132755253804623E1,(-0.572619091602123242E0),0.131256042042879410E1,(-0.167318635994090555E2),0.770337083611766506E2,(-0.166532418293771445E3),0.145795634982241188E3;
        0.100155911218162056E1,(-0.581602767440235826E0),0.145780859455946740E1,(-0.179845517198366242E2),0.831119080766759496E2,(-0.182264389363994262E3),0.162764692295359923E3;
        0.100162785267412652E1,(-0.584398931555789295E0),0.150520254342668840E1,(-0.184130047714004206E2),0.852907583572585327E2,(-0.188174170798355530E3),0.169443904142544484E3;
        0.100152534517620557E1,(-0.579852983785877696E0),0.142118552271047550E1,(-0.175846939820156156E2),0.806963928000584641E2,(-0.174580419371663937E3),0.152681982191725126E3;
        0.100133650020327079E1,(-0.571016121075420144E0),0.124885541957428578E1,(-0.157920077525599626E2),0.702045676623086305E2,(-0.141825439538750030E3),0.110065964510358111E3;
        0.100110227699732149E1,(-0.559454798568633391E0),0.101103403142494082E1,(-0.131824316840881615E2),0.540948351244550463E2,(-0.887758470577307833E2),0.372643579228733312E2;
        0.100084985404777311E1,(-0.546321697851663421E0),0.726279894861903711E0,(-0.988901217971871359E1),0.326648422382974873E2,(-0.143932982605944289E2),(-0.703286466392767517E2);
        0.100060044651513586E1,(-0.532645068296426763E0),0.413734218234089265E0,(-0.607903165652923887E1),0.653537117926391956E1,0.811968674174817938E2,(-0.216062509103118219E3);
        0.100037084074919880E1,(-0.519367798755859954E0),0.937695883815620208E-1,(-0.196590218244530879E1),(-0.232116707527690251E2),0.195957345765519185E3,(-0.400567464662935954E3);
        0.100017386087863812E1,(-0.507342914081992991E0),(-0.212152953451164824E0),0.218577482173420794E1,(-0.549103369363771352E2),0.325061426070844601E3,(-0.619701832133900510E3);
        0.100001853304761425E1,(-0.497315029957268600E0),(-0.481956552752309278E0),0.605812548574102446E1,(-0.861793389006440498E2),0.459753494542378450E3,(-0.861497622843689967E3);
        0.999910203537689782E0,(-0.489899028164323543E0),(-0.693540488023821745E0),0.927842024023405035E1,(-0.113755427357986322E3),0.585724383885138662E3,(-0.110132479636645595E4);
        0.999851296077879991E0,(-0.485606376251161698E0),(-0.823914442592802466E0),0.113908222174320769E2,(-0.133013259166651425E3),0.679385684367357033E3,(-0.129118134483095994E4);
        0.999845081672796069E0,(-0.485141076970931875E0),(-0.838395344585816197E0),0.116305255908131120E2,(-0.135238334189161982E3),0.690363317878166812E3,(-0.131365879040396779E4);
        0.999875084936594602E0,(-0.487713464893235645E0),(-0.746469233907073686E0),0.987791795220852637E1,(-0.116436657882360846E3),0.582754098417843628E3,(-0.105695507426972295E4);
        0.999915207543239031E0,(-0.491403404232152847E0),(-0.605027287926792024E0),0.698540127976806025E1,(-0.831526474081199967E2),0.378423526757795288E3,(-0.534127481763225025E3);
        0.999953256045163139E0,(-0.495160520197658480E0),(-0.450393548400374111E0),0.358995723445746928E1,(-0.412003905413793880E2),0.101884399974314999E3,0.225656543966090058E3;
        0.999982628982790979E0,(-0.498281758523431014E0),(-0.312147636380610568E0),0.323072315396179830E0,0.224018892826841484E1,(-0.206302353722247626E3),0.113699347739655984E4;
        0.100000060528608978E1,(-0.500346372455203890E0),(-0.213303749600065912E0),(-0.220182825964011945E1),0.385352003416114248E2,(-0.484680224675335511E3),0.202701024667479777E4;
        0.100000735441695697E1,(-0.501188775593836491E0),(-0.169470946451388737E0),(-0.341885360481345726E1),0.575524954323045604E2,(-0.643252215173724597E3),0.257823197095091063E4;
        0.100000530523206392E1,(-0.500890894862621748E0),(-0.187518721505961017E0),(-0.283549714276228414E1),0.469429644543382175E2,(-0.540311979370439276E3),0.216194811209957399E4;
        0.100000218489524248E1,(-0.500394032080561836E0),(-0.220509403482347808E0),(-0.166633046237395479E1),0.236182861502088283E2,(-0.291950258456589229E3),0.105920994365810175E4;
        0.100000040794103827E1,(-0.500077894159801120E0),(-0.243965723606567259E0),(-0.737277530085167176E0),0.290038256588430492E1,(-0.453150503298410144E2),(-0.165294805805990258E3);
        0.999999943680199164E0,(-0.499984501575369033E0),(-0.251802161307350898E0),(-0.386195589153743982E0),(-0.595735325721531152E1),0.740161731792962763E2,(-0.835964066992696745E3);
        0.999999984883699454E0,(-0.499995194804988608E0),(-0.250644104361886045E0),(-0.453185013346399842E0),(-0.377433250302271612E1),0.360187349746899597E2,(-0.559984941564874659E3);
        0.999999999258223663E0,(-0.499999676064288333E0),(-0.250059820479931515E0),(-0.493978580507823741E0),(-0.216540420856374751E1),0.202223950652840076E1,(-0.259266911626180843E3);
        0.99999999999149071E0,(-0.499999993452805506E0),(-0.250002123214943715E0),(-0.499624982164295870E0),(-0.185122284349342464E1),(-0.741496784220146826E1),(-0.139575861071572860E3);
        0.100000000000000000E1,(-0.499999999999977639E0),(-0.250000000257976796E0),(-0.499999519716801030E0),(-0.181282523493989523E1),(-0.962014165795826789E1),(-0.831590970563825627E2);
        0.100000000000000000E1,(-0.499999999999977639E0),(-0.250000000257976796E0),(-0.499999519716801030E0),(-0.181282523493989523E1),(-0.962014165795826789E1),(-0.831590970563825627E2)]; % duplicated last row to allow inf's.
%%    
    else % if 2 outputs requested (also derivative, which requires more accurate table).
%%        
        limits=[0,9029,19039,29089,39207,49422,59767,70397,81488,93124,105396,...
            118742,134183,151059,165541,179303,192715,205944,219086,232207,245355,...
            258571,271889,285333,298939,312752,326775,341080,355688,370644,386004,...
            401838,418180,435276,453278,472586,494295,520200,542030,562561,582485,...
            602097,621552,640941,660333,679781,699313,718990,738829,758836,779055,...
            799539,820257,841292,862638,884320,906364,928751,951552,974799,998585,...
            1022836,1047722,1073238,1099450,1126350,1154230,1183145,1213152,1244895,...
            1278871,1316815,1366676,1405012,1440973,1475766,1509862,1543509,1576858,...
            1610009,1643040,1675999,1708926,1741830,1774778,1807741,1840786,1873899,...
            1907090,1940367,1973737,2007205,2040776,2074454,2108243,2142146,2176166,...
            2210272,2244502,2278896,2313597,2348704,2384193,2420075,2456323,2493035,...
            2530186,2567794,2605879,2644413,2683468,2723130,2763376,2804177,2845633,...
            2887862,2930849,2974654,3019256,3064925,3111671,3159622,3208789,3259671,...
            3312214,3367241,3425239,3487588,3557051,3639015,3708322,3773632,3837115,...
            3899635,3959158,4031702,4115420,4211381,4294405,4374870,4455082,4536256,...
            4619304,4705046,4794502,4888835,4989702,5100526,5228929,5396315,5537604,...
            5678775,5825187,5980808,6150248,6340543,6566210,6877100,7198644,7547657,...
            7959044,8472086,9139562,10031454,11300133,13281994,inf]'*(1/1048576);
        CutoffLimit=(3899635/1048576);
        tbl = [0,0.200000000000000318E1,(-0.265998226686983416E-10),(-0.399999996395850651E1),(-0.178601709177072891E-4),0.750400074737995418E1,(-0.413101215060839650E0);
            0.172188974057477484E-1,0.199911047100421550E1,(-0.103280838069362725E0),(-0.399444208236158272E1),0.322499861995425444E0,0.748204172704239215E1,(-0.149089792114261015E1);
            0.362900816337490777E-1,0.199604794964498974E1,(-0.217435780295645649E0),(-0.397533483480231665E1),0.677501066612199674E0,0.739655094045475774E1,(-0.253034027319801906E1);
            0.553975896159390535E-1,0.199078711426436162E1,(-0.331301480672133512E0),(-0.394261099187645568E1),0.102838596509968682E1,0.725090141158678677E1,(-0.353456351838725595E1);
            0.745728657597642320E-1,0.198329621090389123E1,(-0.444792320915775294E0),(-0.389623057406556012E1),0.137319515257949276E1,0.704608226804629851E1,(-0.448980476332832350E1);
            0.938479063680716566E-1,0.197352617916689081E1,(-0.557814569008166792E0),(-0.383611722110231291E1),0.170993040999727082E1,0.678342160677626814E1,(-0.538270943309247087E1);
            0.113260282827360694E0,0.196140639009406975E1,(-0.670290241840569757E0),(-0.376213901480512860E1),0.203661276851164554E1,0.646463806303536992E1,(-0.620475492008473185E1);
            0.133071370710301156E0,0.194666509638673525E1,(-0.783384764311255306E0),(-0.367303946198182958E1),0.235465130360759740E1,0.608711389433092198E1,(-0.694969764756820197E1);
            0.153569681248276728E0,0.192887179165358821E1,(-0.898284886418604029E0),(-0.356677135612028110E1),0.266484006020179102E1,0.564583580636770936E1,(-0.760348202448806365E1);
            0.174858833838780228E0,0.190763266306258237E1,(-0.101498143371473542E1),(-0.344174031154011155E1),0.296398767248009366E1,0.513919582891103721E1,(-0.814534864726969603E1);
            0.197040311649121461E0,0.188248022435928135E1,(-0.113330658048814938E1),(-0.329620620295032316E1),0.324792835705407672E1,0.456676277770070270E1,(-0.855642859651413895E1);
            0.220809725810127879E0,0.185205682628039650E1,(-0.125591863641995402E1),(-0.312380599791916576E1),0.351771668791713994E1,0.391260897463622840E1,(-0.881139791567140899E1);
            0.247800383856437291E0,0.181308196329716248E1,(-0.138922365180145844E1),(-0.290868136683279752E1),0.377712891743941443E1,0.313227866333505191E1,(-0.885014001046422601E1);
            0.276608791061047187E0,0.176616878193075342E1,(-0.152367055561611990E1),(-0.265814635887265189E1),0.399483729795736700E1,0.227673590783385137E1,(-0.866106349084924416E1);
            0.300704053411645368E0,0.172260299996119814E1,(-0.162917915528605306E1),(-0.243356734496401809E1),0.412733418430037371E1,0.155839498517865094E1,(-0.832363474614048649E1);
            0.323026290524481280E0,0.167861876420664353E1,(-0.172069980386726068E1),(-0.221458311975300477E1),0.420816373703810642E1,0.902448378473771286E0,(-0.787400152076307922E1);
            0.344210935535645429E0,0.163354932417217664E1,(-0.180153138034696575E1),(-0.199813515104229712E1),0.424663638275194113E1,0.297780858219283348E0,(-0.733737277098651893E1);
            0.364529401256864744E0,0.158717253668601375E1,(-0.187309899443659142E1),(-0.178365093856265115E1),0.424799173608643433E1,(-0.257933365438357782E0),(-0.673490941024932303E1);
            0.384124098146076028E0,0.153941360972903937E1,(-0.193616739356274304E1),(-0.157135778112187359E1),0.421605461720875705E1,(-0.764614100307950128E0),(-0.608534662953025014E1);
            0.403080888858180219E0,0.149025327358351708E1,(-0.199121169045801069E1),(-0.136176879971276564E1),0.415402324246473337E1,(-0.122164674718752819E1),(-0.540555400173687875E1);
            0.421451391279953657E0,0.143970831256258627E1,(-0.203854438712077968E1),(-0.115555497026391755E1),0.406478725106562866E1,(-0.162841415478200680E1),(-0.471071683862872583E1);
            0.439271084927360091E0,0.138780330796774102E1,(-0.207839751973158166E1),(-0.953404012773115385E0),0.395104617262968367E1,(-0.198468131400627805E1),(-0.401441022802679874E1);
            0.456560492062716257E0,0.133457842654743941E1,(-0.211094319306816604E1),(-0.756040634564553512E0),0.381539938304851956E1,(-0.229057592416083939E1),(-0.332886290542163744E1);
            0.473322891132214689E0,0.128010779517122902E1,(-0.213630973295693573E1),(-0.564274316864793876E0),0.366045515500684696E1,(-0.254658595638848791E1),(-0.266456567478372755E1);
            0.489572359131545910E0,0.122441420065478170E1,(-0.215463421638995679E1),(-0.378690628812216920E0),0.348860875281023880E1,(-0.275393371938976799E1),(-0.202995825547005706E1);
            0.505327037125503014E0,0.116748209849389019E1,(-0.216603139454837584E1),(-0.199739138448795196E0),0.330203413362440159E1,(-0.291421948067263601E1),(-0.143282460549707578E1);
            0.520552451036728188E0,0.110947175156186760E1,(-0.217057198567320573E1),(-0.283823142381660503E-1),0.310342018292736551E1,(-0.302902694431265958E1),(-0.878989611063809127E0);
            0.535284272911387934E0,0.105026365939849234E1,(-0.216834543508467483E1),0.135286946021039734E0,0.289444178447663077E1,(-0.310077240769332245E1),(-0.372790617719553938E0);
            0.549495423976270493E0,0.989957517133847240E0,(-0.215940479768487946E1),0.290541851114756736E0,0.267745258525648001E1,(-0.313170737406919779E1),0.819998901074793382E-1;
            0.563176987608668216E0,0.928565424591963960E0,(-0.214379532251842588E1),0.436931211530099768E0,0.245444118056304270E1,(-0.312444674890172185E1),0.483171809457290048E0;
            0.576320495900127110E0,0.866070328793421185E0,(-0.212153212165338784E1),0.574072170103172975E0,0.222722674414218038E1,(-0.308172318832373337E1),0.829576464386321378E0;
            0.588916901670149952E0,0.802420611848573062E0,(-0.209258411843575865E1),0.701630990543058687E0,0.199745077584638410E1,(-0.300627241942777185E1),0.112049726679702372E1;
            0.600917085520115129E0,0.737735615074219021E0,(-0.205698131263589361E1),0.818934525234090945E0,0.176732636786767411E1,(-0.290123650333106373E1),0.135710267443940671E1;
            0.612402020950764484E0,0.671344194353154544E0,(-0.201423109231541479E1),0.926598144512634273E0,0.153627647817142711E1,(-0.276819170816223315E1),0.154070783804334652E1;
            0.623338828368507678E0,0.603032602124701268E0,(-0.196392869315710494E1),0.102409451929493788E1,0.130550455311101676E1,(-0.260918684909169191E1),0.167219589537006268E1;
            0.633783446966695194E0,0.531779636565191471E0,(-0.190486122481219358E1),0.111161252426984996E1,0.107381516587410722E1,(-0.242411279295907010E1),0.175246209909700942E1;
            0.643986625850184609E0,0.454371081551731005E0,(-0.183326771697563029E1),0.119045935404344817E1,0.834156225084478084E0,(-0.220584159580657025E1),0.177712875741324521E1;
            0.654111168823941873E0,0.366015601315767390E0,(-0.174230505145137021E1),0.125996341397365558E1,0.577936563303165906E0,(-0.194205006869635281E1),0.174521551745133482E1;
            0.660987464051572608E0,0.295127864348986008E0,(-0.166227999870928649E1),0.129998874106192911E1,0.387103877308191678E0,(-0.172388789140643224E1),0.168159286443939922E1;
            0.666138573047920731E0,0.231538876987214011E0,(-0.158515436547654206E1),0.132395009836815202E1,0.227977645688123980E0,(-0.152623524009442850E1),0.159881687405371987E1;
            0.669974851928478440E0,0.172739093139033286E0,(-0.150929293369184993E1),0.133598638875419554E1,0.916045301543736660E-1,(-0.134389711393501969E1),0.150372703256704621E1;
            0.672686440091307852E0,0.117684748833188238E0,(-0.143422312607704973E1),0.133833523717944728E1,(-0.262159388184617713E-1),(-0.117511116351812762E1),0.140110792079802535E1;
            0.674384755393544594E0,0.658451427732252733E-1,(-0.135985649042424763E1),0.133252338528952370E1,(-0.128028877751246672E0),(-0.101912105027936166E1),0.129458105644425338E1;
            0.675145743848323530E0,0.169184876801461371E-1,(-0.128626306172836354E1),0.131973318532105074E1,(-0.215645692166370855E0),(-0.875494157188311335E0),0.118693145157151373E1;
            0.675027027374721094E0,(-0.293087623319485215E-1),(-0.121353882022181578E1),0.130093670539195766E1,(-0.290546156221157018E0),(-0.743801916131689989E0),0.108028744206497545E1;
            0.674074250846632931E0,(-0.729892122370421305E-1),(-0.114179838816497987E1),0.127696081499458345E1,(-0.353982324061309776E0),(-0.623608043221767823E0),0.976314212146214241E0;
            0.672326706444780992E0,(-0.114206457280162213E0),(-0.107121537437263138E1),0.124854852156078844E1,(-0.407014072183311531E0),(-0.514518875320300393E0),0.876206670800656241E0;
            0.669814549817330054E0,(-0.153102199019882675E0),(-0.100181898312994905E1),0.121630127523156540E1,(-0.450693452812298959E0),(-0.415898148283916139E0),0.780837871654716446E0;
            0.666567428105273244E0,(-0.189717206014801046E0),(-0.933776584524663795E0),0.118080989174871284E1,(-0.485875038983429380E0),(-0.327297714902266888E0),0.690925159232017915E0;
            0.662615786224208039E0,(-0.224074498752027098E0),(-0.867269118404771676E0),0.114263204137521678E1,(-0.513355487133520785E0),(-0.248240259836454494E0),0.606879724152258434E0;
            0.657980767469523989E0,(-0.256260818566166285E0),(-0.802333015910945523E0),0.110220129671898640E1,(-0.533931654550177503E0),(-0.178066961854015778E0),0.528839053596420447E0;
            0.652676649091732649E0,(-0.286362253626692190E0),(-0.738972965118577013E0),0.105987904821614254E1,(-0.548323184064576735E0),(-0.116126734878396276E0),0.456948915974556727E0;
            0.646738244982729145E0,(-0.314339548603892438E0),(-0.677441244753827216E0),0.101616062368164850E1,(-0.557144098060668639E0),(-0.619956921802726743E-1),0.391175819827975523E0;
            0.640167917606090116E0,(-0.340310469501187762E0),(-0.617636362741410360E0),0.971267848479420800E0,(-0.561024038450997179E0),(-0.149547133241913096E-1),0.331362700389018361E0;
            0.632992313530838592E0,(-0.364268499490612109E0),(-0.559715061322960087E0),0.925578418962635301E0,(-0.560507698510212346E0),0.254775686687863293E-1,0.277368591309827692E0;
            0.625228895275415809E0,(-0.386248156592644614E0),(-0.503733830719151740E0),0.879376651401619481E0,(-0.556114469554697581E0),0.598493953072244266E-1,0.228947783844675184E0;
            0.616894311744311549E0,(-0.406282605545519327E0),(-0.449741405522701981E0),0.832919375459345635E0,(-0.548323807039116072E0),0.886871825419941611E-1,0.185856765612352918E0;
            0.608023207660676067E0,(-0.424368746968400194E0),(-0.397883559460544448E0),0.786533150142492734E0,(-0.537602306086556262E0),0.112458649094667719E0,0.147769897141333789E0;
            0.598615259304393018E0,(-0.440578769320728070E0),(-0.348087830611461307E0),0.740335211521965113E0,(-0.524342447781010095E0),0.131703168633023781E0,0.114313245108928485E0;
            0.588684450613535919E0,(-0.454944071605281111E0),(-0.300379545118866462E0),0.694508630523179225E0,(-0.508914070004716251E0),0.146878420411441941E0,0.851150561700060683E-1;
            0.578217862055735474E0,(-0.467523196654718497E0),(-0.254670385202455259E0),0.649107262027468493E0,(-0.491610492340846458E0),0.158430219709300458E0,0.598769421297061887E-1;
            0.567276864366820945E0,(-0.478285509781965251E0),(-0.211191463582689801E0),0.604490495180860775E0,(-0.472820681297626750E0),0.166712156508202723E0,0.382574694740012421E-1;
            0.555814623826241625E0,(-0.487313539574512423E0),(-0.169727556127026652E0),0.560553671193840722E0,(-0.452724359844100069E0),0.172133269630414978E0,0.199073373312538942E-1;
            0.543863775772071160E0,(-0.494603834334442075E0),(-0.130389648078374156E0),0.517512383035779737E0,(-0.431612881241357739E0),0.175015117130107993E0,0.453862233365959252E-2;
            0.531426250445901378E0,(-0.500179188238960389E0),(-0.931706598781136056E-1),0.475450105646411762E0,(-0.409703063071103229E0),0.175671761229982568E0,(-0.813193382491569379E-2);
            0.518541268260409072E0,(-0.504048138223853892E0),(-0.581674936039204000E-1),0.434561661974689900E0,(-0.387256630669440715E0),0.174400614693168964E0,(-0.184178103634925402E-1);
            0.505106270421981497E0,(-0.506248352330491497E0),(-0.251145157868222483E-1),0.394601453781983814E0,(-0.364272345208964306E0),0.171443345879604955E0,(-0.265956737758513899E-1);
            0.491135191663912385E0,(-0.506763328592400520E0),0.590321813460936035E-2,0.355714008314975107E0,(-0.340942161767219571E0),0.167024487154736345E0,(-0.328781077587547203E-1);
            0.476646138584158844E0,(-0.505582957085671410E0),0.348050908526559716E-1,0.318039567318893830E0,(-0.317451158032342365E0),0.161364346550548458E0,(-0.375107399004394777E-1);
            0.461381343540458893E0,(-0.502635862965252483E0),0.619874096932760685E-1,0.281057392455841391E0,(-0.293545200221179817E0),0.154536248415834198E0,(-0.406957223791195571E-1);
            0.445169240108577073E0,(-0.497772687328213275E0),0.875106605157222630E-1,0.244606313879173338E0,(-0.269151667816028361E0),0.146610147930770524E0,(-0.425814456113940937E-1);
            0.427282457040678296E0,(-0.490528206590168884E0),0.112018535460207663E0,0.207527403487725021E0,(-0.243462458394247322E0),0.137343197081875539E0,(-0.432048061909662947E-1);
            0.404231661899906905E0,(-0.478568515734296423E0),0.138464418955144739E0,0.164232293402068970E0,(-0.212272791184509557E0),0.125004981968114127E0,(-0.425390701332724329E-1);
            0.386927900159673203E0,(-0.467825816892735759E0),0.154835001621036191E0,0.134818758252054063E0,(-0.190273287991473142E0),0.115668866357546919E0,(-0.412899966748427415E-1);
            0.371071065254815588E0,(-0.456759867742616135E0),0.167408919996230613E0,0.110044138607938393E0,(-0.171165698819795520E0),0.107170062530868414E0,(-0.397135106521281224E-1);
            0.356103361784972384E0,(-0.445311112540478640E0),0.177270824395838081E0,0.884771286587795669E-1,(-0.154039624310218421E0),0.992623426153844392E-1,(-0.379425046072274956E-1);
            0.341813717604111809E0,(-0.433522657185645858E0),0.184957992849487205E0,0.694652560920614718E-1,(-0.138501240816554596E0),0.918593528842372550E-1,(-0.360635525015966637E-1);
            0.328095316109839527E0,(-0.421455937965748609E0),0.190819178217045857E0,0.526101961828662739E-1,(-0.124318352397344489E0),0.849161545614732975E-1,(-0.341363797726042510E-1);
            0.314885877285488062E0,(-0.409174203174658527E0),0.195111141293299660E0,0.376318342565439599E-1,(-0.111331062432231779E0),0.784025860393085868E-1,(-0.322031567413290108E-1);
            0.302145828344396368E0,(-0.396738070309490620E0),0.198036985823824896E0,0.243160943108299119E-1,(-0.994185083740873754E-1),0.722946541586370780E-1,(-0.302936111698002614E-1);
            0.289845432037797178E0,(-0.384201110509052605E0),0.199765148267713047E0,0.124874802567636851E-1,(-0.884809806510697910E-1),0.665699365156675492E-1,(-0.284287611238599087E-1);
            0.277966831855919008E0,(-0.371616672645312366E0),0.200438425379190676E0,0.200293114136139002E-2,(-0.784384344278813514E-1),0.612095119935399513E-1,(-0.266233178446914867E-1);
            0.266495093468847949E0,(-0.359031981730437377E0),0.200181604754466522E0,(-0.726237178443652473E-2),(-0.692202215652102280E-1),0.561945747933121889E-1,(-0.248875853219179445E-1);
            0.255425603799918490E0,(-0.346498445390963179E0),0.199105972463762714E0,(-0.154128508010185777E-1),(-0.607694391161019441E-1),0.515098830798217210E-1,(-0.232270942587615095E-1);
            0.244734092610272911E0,(-0.334038911059221719E0),0.197308727240714855E0,(-0.225566012332437775E-1),(-0.530193328460481987E-1),0.471320912355528139E-1,(-0.216453676888117648E-1);
            0.234427489936615908E0,(-0.321706964802080566E0),0.194881417867114231E0,(-0.287711366414493925E-1),(-0.459305798071078401E-1),0.430505331402570292E-1,(-0.201436868078083263E-1);
            0.224481763276044379E0,(-0.309515176538991436E0),0.191900804881248156E0,(-0.341460482535868405E-1),(-0.394458275809533110E-1),0.392427972703205041E-1,(-0.187213862364319682E-1);
            0.214897834801347496E0,(-0.297502030830759205E0),0.188441967514776817E0,(-0.387491386112610896E-1),(-0.335283677517530323E-1),0.356966827817790801E-1,(-0.173778473503612586E-1);
            0.205668428465662882E0,(-0.285692921500898659E0),0.184571840499748540E0,(-0.426476502996768410E-1),(-0.281387399699765214E-1),0.323973417933630745E-1,(-0.161110522826568952E-1);
            0.196786342040769428E0,(-0.274110284003138780E0),0.180351589557357083E0,(-0.459036422044098005E-1),(-0.232402849885145786E-1),0.293306215095499734E-1,(-0.149184343152105127E-1);
            0.188244178698584155E0,(-0.262773544409050858E0),0.175837062640405069E0,(-0.485746113493403546E-1),(-0.187987472762389415E-1),0.264830090735208470E-1,(-0.137970777353492839E-1);
            0.180034617835755827E0,(-0.251699723950933801E0),0.171079402769986467E0,(-0.507138342166537903E-1),(-0.147822042470668740E-1),0.238417315189342143E-1,(-0.127438523892285228E-1);
            0.172149929049321870E0,(-0.240903000418616608E0),0.166125182457041308E0,(-0.523708740960354880E-1),(-0.111606297665524120E-1),0.213945963760807187E-1,(-0.117555150406541153E-1);
            0.164582265285446269E0,(-0.230395273249001560E0),0.161016887678904344E0,(-0.535917876272186482E-1),(-0.790588611428531043E-2),0.191300730697283114E-1,(-0.108287988976758361E-1);
            0.157323470336728865E0,(-0.220186054078662285E0),0.155793080959939602E0,(-0.544194213574966950E-1),(-0.499149311922628065E-2),0.170372132807012838E-1,(-0.996047824010267684E-2);
            0.150365341862377537E0,(-0.210282970987498935E0),0.150488833259206676E0,(-0.548935980825494500E-1),(-0.239260985766658785E-2),0.151056969874201304E-1,(-0.914741387165633192E-2);
            0.143699450836519043E0,(-0.200691641799104840E0),0.145135825335631459E0,(-0.550513445248673816E-1),(-0.858415811913161436E-4),0.133257788493644653E-1,(-0.838693831063794240E-2);
            0.137323402511177748E0,(-0.191424923794669027E0),0.139767922389139326E0,(-0.549273057048483269E-1),0.194894519290670794E-2,0.116896961856167953E-1,(-0.767606378544552737E-2);
            0.131221510598143534E0,(-0.182474943424575187E0),0.134405133852460914E0,(-0.545535874862542181E-1),0.373492083973658751E-2,0.101868310695895953E-1,(-0.701129109480848885E-2);
            0.125378893271469998E0,(-0.173833280805678521E0),0.129064533728401446E0,(-0.539589057256028482E-1),0.529307909600655648E-2,0.880745213780931106E-2,(-0.638855486637231200E-2);
            0.119765549362634615E0,(-0.165467363727582434E0),0.123745332625101287E0,(-0.531664143021108356E-1),0.664608239047091487E-2,0.753932265253523624E-2,(-0.580388700486523147E-2);
            0.114362321506446496E0,(-0.157358964437055456E0),0.118452615089369085E0,(-0.521961978767288143E-1),0.781118376563328795E-2,0.637381643572229613E-2,(-0.525522022876853253E-2);
            0.109170187670980141E0,(-0.149519036729348020E0),0.113208935313888198E0,(-0.510697853218228825E-1),0.880005283034885530E-2,0.530702945271542388E-2,(-0.474130584869591499E-2);
            0.104184217341393734E0,(-0.141949036830033508E0),0.108030008485887338E0,(-0.498068980520694063E-1),0.962533103362234653E-2,0.433395288525288827E-2,(-0.426091393888069523E-2);
            0.994042637873888365E-1,(-0.134657041923721962E0),0.102935429184421450E0,(-0.484276835060307331E-1),0.102985604795864240E-1,0.345052362837574469E-2,(-0.381230369496327043E-2);
            0.948138614157064280E-1,(-0.127625531244206087E0),0.979260201759184164E-1,(-0.469463958522358754E-1),0.108329871415151378E-1,0.265003391971599136E-2,(-0.339388718998469535E-2);
            0.904129486761472332E-1,(-0.120861348300067013E0),0.930187832743370567E-1,(-0.453809002636123503E-1),0.112389994236412579E-1,0.192890379539168970E-2,(-0.300462938839964723E-2);
            0.861957418333438194E-1,(-0.114362003963547569E0),0.882234780154013118E-1,(-0.437464780089845163E-1),0.115273735863978884E-1,0.128265451629843544E-2,(-0.264328610241105372E-2);
            0.821563431555205322E-1,(-0.108124240015725203E0),0.835485582312895423E-1,(-0.420573617773663592E-1),0.117084213936640420E-1,0.706960845984960897E-3,(-0.230887275767935654E-2);
            0.782936626282283169E-1,(-0.102151670259819415E0),0.790070343382139350E-1,(-0.403290202922479330E-1),0.117919461915606306E-1,0.198180589739912053E-3,(-0.200019813643679494E-2);
            0.745964881395443104E-1,(-0.964317183413394273E-1),0.745989751292402047E-1,(-0.385715384164957173E-1),0.117876072085111161E-1,(-0.248532182264607591E-3),(-0.171573987207757127E-2);
            0.710536597305496858E-1,(-0.909513659348333020E-1),0.703231127600360679E-1,(-0.367935035228507130E-1),0.117041388081056798E-1,(-0.637622974076562632E-3),(-0.145447244260377941E-2);
            0.676643440658894565E-1,(-0.857131091691964981E-1),0.661895782961275362E-1,(-0.350076481267477930E-1),0.115499683515435717E-1,(-0.972269800670038673E-3),(-0.121574359262321511E-2);
            0.644273514454620100E-1,(-0.807184221503400699E-1),0.622073537889767758E-1,(-0.332261241615565044E-1),0.113335117110629607E-1,(-0.125582929161808161E-2),(-0.998498441229914323E-3);
            0.613313144396029435E-1,(-0.759526391591089794E-1),0.583719942192031362E-1,(-0.314546822893598114E-1),0.110621457922076792E-1,(-0.149243826499020556E-2),(-0.801404047176492748E-3);
            0.583651430400751062E-1,(-0.714012201989088703E-1),0.546783412381742662E-1,(-0.296979243977078787E-1),0.107424014287428025E-1,(-0.168582857004849555E-2),(-0.623541157712955196E-3);
            0.555278858794431530E-1,(-0.670648757840687719E-1),0.511330254293757011E-1,(-0.279655515766935916E-1),0.103813802777457880E-1,(-0.183895333362114330E-2),(-0.464134131281982627E-3);
            0.528134338430215718E-1,(-0.629360576462760551E-1),0.477355278447984026E-1,(-0.262635640061829140E-1),0.998534827598058774E-2,(-0.195503274972557181E-2),(-0.322390839586588452E-3);
            0.502207781455173515E-1,(-0.590146354662675983E-1),0.444909822713341637E-1,(-0.246004940589955418E-1),0.956102178771131711E-2,(-0.203709429864613447E-2),(-0.197219680835138007E-3);
            0.477328893172592832E-1,(-0.552760434939634941E-1),0.413838042214722342E-1,(-0.229738031909293018E-1),0.911199812853324579E-2,(-0.208840618477788804E-2),(-0.876198557842924979E-4);
            0.453489049292775621E-1,(-0.517200131224836975E-1),0.384180566701486507E-1,(-0.213905954774081951E-1),0.864405650314177672E-2,(-0.211162541087703379E-2),0.715934753822845722E-5;
            0.430620991258915751E-1,(-0.483372612067312808E-1),0.355899439991329733E-1,(-0.198535817375202642E-1),0.816162385352477587E-2,(-0.210943662923231438E-2),0.878796336509490544E-4;
            0.408718390808845477E-1,(-0.451273216872013627E-1),0.329026790093692958E-1,(-0.183690072268617183E-1),0.767011604621344415E-2,(-0.208452391123471972E-2),0.155542857330921916E-3;
            0.387574600788209935E-1,(-0.420604365197892787E-1),0.303346130422965482E-1,(-0.169289700573747217E-1),0.716997977192620906E-2,(-0.203902862699030588E-2),0.210955050147784300E-3;
            0.367239393166237471E-1,(-0.391443441594937249E-1),0.278952095750624700E-1,(-0.155425177116896786E-1),0.666716568311591964E-2,(-0.197542678785568384E-2),0.254948835164312714E-3;
            0.347443536680594961E-1,(-0.363412125124219296E-1),0.255556357720951089E-1,(-0.141966687418506678E-1),0.615945706785575376E-2,(-0.189496503808960987E-2),0.288319016791461258E-3;
            0.328101149724346355E-1,(-0.336404021345767137E-1),0.233098280551486238E-1,(-0.128909181916942431E-1),0.564869523825074678E-2,(-0.179909546891291202E-2),0.311641917344884185E-3;
            0.308896078744790145E-1,(-0.310004587100481848E-1),0.211264256445317018E-1,(-0.116097158418243087E-1),0.513039492724783790E-2,(-0.168770080199083202E-2),0.325301978805141445E-3;
            0.289254130738359798E-1,(-0.283484540124524946E-1),0.189494393360908069E-1,(-0.103224335824396812E-1),0.459281247635752177E-2,(-0.155806360435158047E-2),0.328853645486811398E-3;
            0.268205199667249023E-1,(-0.255667371723130916E-1),0.166899368123274214E-1,(-0.897846619443708413E-2),0.401397987429304727E-2,(-0.140364199142447763E-2),0.322634106661618810E-3;
            0.252010490520106222E-1,(-0.234736193516672881E-1),0.150108614836069606E-1,(-0.797668713389591242E-2),0.357120059133070829E-2,(-0.127560583532831292E-2),0.311064672709286834E-3;
            0.237953647950609947E-1,(-0.216932081580546903E-1),0.136005020782481031E-1,(-0.713494783248382073E-2),0.319199724908096338E-2,(-0.115930432964430994E-2),0.296241138200582522E-3;
            0.225303214834544853E-1,(-0.201221013486810608E-1),0.123722935199896218E-1,(-0.640312461990953268E-2),0.285729392099952280E-2,(-0.105166008102112513E-2),0.279325486179968443E-3;
            0.689939794318120130E-3,0.913368683562267240E0,0.530965958947151856E1,(-0.105636958077185447E3),0.145155318471829249E4,(-0.893607056585779440E4),0.204199555600754049E5;
            0.950623646968698991E-3,0.891088703013461166E0,0.610314170416361538E1,(-0.120709661680292458E3),0.161261801022470834E4,(-0.985406918839951636E4),0.226002000512076687E5;
            0.110118602778413029E-2,0.877755039796607329E0,0.659519180167157328E1,(-0.130394805935360936E3),0.171985971682159079E4,(-0.104874406733452617E5),0.241589649021064577E5;
            0.113078040069008893E-2,0.875058900542912839E0,0.669752457230783863E1,(-0.132466065409907740E3),0.174343861582941122E4,(-0.106305790119188912E5),0.245209742586573017E5;
            0.105393360455063705E-2,0.882513195982633904E0,0.639621119815261395E1,(-0.125969692546754882E3),0.166464558919114151E4,(-0.101208434886786962E5),0.231468307500856105E5;
            0.926671099837090306E-3,0.895328124601637426E0,0.585848732996017575E1,(-0.113934868565447797E3),0.151312166551872176E4,(-0.910328393795321217E4),0.202993186884702032E5;
            0.775293896603619766E-3,0.911141710293795291E0,0.517011186637625632E1,(-0.979519716622376715E2),0.130436301943825411E4,(-0.764893551158489550E4),0.160773261113940242E5;
            0.616614774343068918E-3,0.928328170705272305E0,0.439444123097720706E1,(-0.792794713349348977E2),0.105149983625423356E4,(-0.582250604293926296E4),0.105800899638665501E5;
            0.462656625659657395E-3,0.945614179847302506E0,0.358569731592239760E1,(-0.590975962175637867E2),0.768184556217153368E3,(-0.370115438815729850E4),0.396128573090470613E4;
            0.322041067485281307E-3,0.961983516476020499E0,0.279163668747230422E1,(-0.385523615754029484E2),0.469145983623663688E3,(-0.137960365292822882E4),(-0.354895802564696925E4);
            0.200550890549943789E-3,0.976654645888794723E0,0.205337190621994952E1,(-0.187372298093197625E2),0.169959615055911842E3,0.102987383866561930E4,(-0.116348923557857226E5);
            0.101628626523068236E-3,0.989057154759761169E0,0.140540412714730708E1,(-0.680643608787858362E0),(-0.113101411875640262E3),0.339668129975937663E4,(-0.198814793395649192E5);
            0.267626810324153818E-4,0.998814467146904307E0,0.875487387912850991E0,0.146700013869018385E2,(-0.363257471164034513E3),0.557106946781724906E4,(-0.277572822294869583E5);
            (-0.244018291906972802E-4),0.100575855138164509E1,0.482754129694769927E0,0.265175088780692625E2,(-0.564317991917401573E3),0.739107787436511342E4,(-0.346225402343289137E5);
            (-0.533958248603787785E-4),0.100986694654496329E1,0.240159448968904839E0,0.341584254134880073E2,(-0.699708669288727152E3),0.867071721821041482E4,(-0.396625587849906614E5);
            (-0.615093835049618748E-4),0.101106579979061748E1,0.166346246249902064E0,0.365823861632234898E2,(-0.744486656840883907E3),0.911190894066064610E4,(-0.414739159773308828E5);
            (-0.529978127940565751E-4),0.100970859395898185E1,0.256532590124619327E0,0.333856679306873658E2,(-0.680739662486245343E3),0.843382650585232205E4,(-0.384681015538006849E5);
            (-0.398892922966849060E-4),0.100751420794075511E1,0.409616870515681067E0,0.276890608307518997E2,(-0.561479959369678605E3),0.710202643047694573E4,(-0.322702370966330567E5);
            (-0.268142952500494636E-4),0.100521394433569849E1,0.578261075395516684E0,0.210937840608810699E2,(-0.416373679524888235E3),0.539905587093898724E4,(-0.239413725727856113E5);
            (-0.158830759007100898E-4),0.100319125442181254E1,0.734234642340224723E0,0.146780884959555495E2,(-0.267906178943831814E3),0.356636090219497098E4,(-0.145135769832107499E5);
            (-0.790886623331063833E-5),0.100163651663825625E1,0.860561087620752742E0,0.920277292061738199E1,(-0.134392510593781122E3),0.182967889478341468E4,(-0.509938624431524827E4);
            (-0.288443110682696826E-5),0.100060124087697812E1,0.949461485637632769E0,0.513046599285279121E1,(-0.294405604453513145E2),0.386799034246481725E3,0.316764744736209750E4;
            (-0.308171566838821480E-6),0.100003768948068412E1,0.100083928737134989E1,0.263169644117890222E1,0.389364318125228869E2,(-0.611368941894292003E3),0.924056864460926465E4;
            0.538135334650703229E-6,0.999840006222274704E0,0.102008498743146811E1,0.163208484292785568E1,0.681502497909418518E2,(-0.106686314894068219E4),0.122006708944696371E5;
            0.436771967815371083E-6,0.999866991617033993E0,0.101709342998645750E1,0.180885848150637384E1,0.622776277837796003E2,(-0.962862846273979519E3),0.114336076474602868E5;
            0.208220499496330294E-6,0.999931523302024040E0,0.100949755727305698E1,0.228595741877070557E1,0.454125124152292432E2,(-0.644738843971388295E3),0.893199792765281453E4;
            0.754497970602527254E-7,0.999972623589395325E0,0.100419315084307401E1,0.265129140735067438E1,0.312503277627204102E2,(-0.351760895749890155E3),0.640505613570052738E4;
            0.220776416508457481E-7,0.999990949979216229E0,0.100156915917796716E1,0.285182433421844750E1,0.226230390221943542E2,(-0.153650190831416912E3),0.450800351039389161E4;
            0.553689324381260947E-8,0.999997367605351351E0,0.100053055324858434E1,0.294156783658422884E1,0.182562455699626424E2,(-0.401980540646745615E2),0.327844604220025274E4;
            0.119467002088464486E-8,0.999999321716228436E0,0.100016355637234534E1,0.297838739076864843E1,0.161749375136881524E2,0.226547657873128918E2,0.248622921330700889E4;
            0.200580857762134253E-9,0.999999858231931579E0,0.100004261461141688E1,0.299296385124181301E1,0.151841872384458081E2,0.586640280137457072E2,0.193945023904000226E4;
            0.217044605213007636E-10,0.999999979567006934E0,0.100000818683383158E1,0.299819527890871592E1,0.147351093047613414E2,0.793156201829320421E2,0.154193527872310842E4;
            0,0.99999999999967749E0,0.100000000372149755E1,0.299999307434128054E1,0.145046843293506420E2,0.957708674441902804E2,0.102866463894076109E4;
            0,0.99999999999967749E0,0.100000000372149755E1,0.299999307434128054E1,0.145046843293506420E2,0.957708674441902804E2,0.102866463894076109E4]; % duplicated last row to allow inf's
%%        
    end;
    
    [dummy,bin] = histc(A,limits);%#ok : dummy cannot be avoided
    x = A(:);
    lrg = A>CutoffLimit;
    bin = bin(:);
%     if any(bin<=0) || any(bin>size(tbl,1))
%         warning('Index out of table range');
%     end;
    invalid = bin==0;
    x(invalid)=nan;
    bin(invalid)=1;
    x(~lrg) = x(~lrg)-limits(bin(~lrg));
    x(lrg) = 1./x(lrg).^2;
    stbl = size(tbl,2);
%     bin(bin>size(tbl,1))=size(tbl,1); % prevent inf's overflowing the table
    tblm = tbl(bin,:); 
    val = tblm(:,stbl);
    for k=stbl-1:-1:1;
        val = val.*x + tblm(:,k);
    end;
    val = reshape(val,size(A));
    return;
end;
if compmode==1
    val = Afun(A, 1);
    val(A>6.5)=val(A>6.5)+1;
%     val(A<=9)=val(A<=9)-1;
    return;
end;
if compmode==2
    tblrng = [.0825 8.1195];
    sml = A < tblrng(1);
    lrg = A > tblrng(2);
    med = ~(sml |lrg);
    if isempty(Etable) || numel(Etable)<3
        Etable{3} = chebyshevApprox(@(Av) Afun(Av.^2,1)+(Av.^2>6.5),38,sqrt(tblrng));
    end;
    val = zeros(size(A));
    AsmlSq = A(sml).^2;
    val(sml) = AsmlSq.*(1+ AsmlSq.*(-1 + AsmlSq.*(1.25 + AsmlSq.* (-2 + AsmlSq.*3.9375))));
    AlrgrSq = 1./A(lrg).^2;
    val(lrg) = 1 - AlrgrSq.*(0.50000000248697 + AlrgrSq .*(0.24999781401184 + AlrgrSq.*(0.50063029950026 +  AlrgrSq.*(1.73404477099860 + AlrgrSq.*13.96281180583811))));
    % [0.50000000248697 0.24999781401184 0.50063029950026 1.73404477099860 13.96281180583811]
    val(med) = chebev( Etable{3}, sqrt(A(med)));
    return;
end;
if compmode==-1
    val = findBestIfunStart;
    return;
end;
zeropnt = 1.221841;
if isempty(Etable) || isempty(Etable{1})
    fprintf('creating table ');
    % error < approx 1e-9
    ws = warning('off');
    Etable{1} = chebyshevApprox(@Afun,23,[0 2*zeropnt]);
    fprintf('.');
    Etable{2} = chebyshevApprox(@Afun,20,[2*zeropnt 7.45]);
    warning(ws);
    fprintf('. done \n');
end;
sel = A< 2* zeropnt;
selA = A(sel);
A( sel ) = selA.^2./(4*zeropnt)+zeropnt; % transform coordinates
rAsq = 1./A.^2;
val = 1-((((2.*rAsq + .5).*rAsq+.25).*rAsq+.5).*rAsq); % series approximation (for large A).
val( sel ) = val( sel ) + chebev(Etable{1}, selA); % update for small A.
sel = (A<7.45) & ~sel;
val(sel) = val(sel) + chebev(Etable{2},A(sel)); % update for intermediate A.

function [val] = Afun(A, dum)
val = zeros(size(A));
dopbar = numel(A)>30;
A = abs(A);
if dopbar
    progressbar('start',numel(A),[],'EstTimeLeft','on');
end;
for k=1:numel(A)
    if A(k)<=6.5
        fun = @(x) ifun(x,A(k));
        val(k) = quadl(fun,eps,A(k)+8, eps);
    else
        offst = max(min( 0.39340331817967 + 0.00015345716910.*A(k).^2 , 1),A(k)-9); % note carefully selected offset to 
        xt = offst:.5:A(k)+9; % could do steps of up to 0.6 before aliasing to 0 frequency. A little lower to improve noise averaging, for unnecessary safety and for easy & accurate scaling.
        res = ifun(xt,A(k));
        [hi,lo] = accurateSum(res);
        val(k) = ((hi-2)+lo)*.5;
    end;
    if dopbar
        progressbar(k);
    end;
end;
if nargin==1 || (dum==0)
    zeropnt = 1.221841;
    A(A < 2*zeropnt) = A( A < 2*zeropnt ).^2./(4*zeropnt)+zeropnt;
    rAsq = 1./A.^2;
    val =val - (A<=6.5) + ((((2.*rAsq + .5).*rAsq+.25).*rAsq+.5).*rAsq);
end;
if dopbar
    progressbar('ready');
end;

function [res] = ifun(x,A)
[y,dy]=logricepdf(x,A,1,logical([0 1 0]));
res = exp(y(:)).*dy.^2;
% plot(x,res,'+');

function [outp] = findBestIfunStart
A=0:.05:7;
offst = (.1965:.00001:.1985); % for .25 steps
% offst = .39:.00001:.41;  % for .5 steps
lgFR = zeros(numel(offst),numel(A));
smres = lgFR;
res_2 = lgFR;

ref = zeros(numel(A),1);
refprt = zeros(numel(A),8);
ref2 = zeros(numel(A),1);
res1 = zeros(numel(A),1);
resed = zeros(numel(A),1);
progressbar('start',numel(A),[],'EstTimeLeft','on');
for m = 1:numel(A)
    acsc  = -17;
    nrmsc = -2;
    res = ifun(0.78822058230988*2^acsc:2^acsc:10+A(m),A(m));
    [hi,lo]=accurateSum(res);
    ref(m) = (hi*2^acsc - 1) + lo*2^acsc;
    [hi,lo]=accurateSum(reshape(res(1:8*floor(numel(res)/8)),8,[])');
    refprt(m,:) = (hi*2^(acsc+3) - 1) + lo*2^(acsc+3);
    
    res1(m) = res(1);
    resed(m) = res(end);
    fun = @(x) ifun(x,A(m));
    ref2(m) = quadl(fun,eps,A(m)+8,eps);
    for k = 1:numel(offst);
        xt2 = offst(k):2^nrmsc:19;
        res2 = ifun(xt2,A(m));
        [hi,lo]=accurateSum(res2);
        lgFR(k,m) = min(log(realmin+abs(fft(res2))));
        smres(k,m) = (hi*2^nrmsc-1)+lo*2^nrmsc;
        res_2(k,m)= res2(1);
    end;
    progressbar(m);
end;
progressbar('ready');
outp.A = A;
outp.offst = offst;
outp.lgFR = lgFR;
outp.smres = smres;
outp.res_2 = res_2;

outp.ref = ref;
outp.refprt = refprt;
outp.ref2 = ref2;
outp.res1 = res1;
outp.resed = resed;

if 0
%% process results of this routine:
    ifo = rice_information_ExpectVal([],-1);
%%
    plot(ifo.A,[ifo.ref-(ifo.ref2-1) ifo.ref*ones(1,8)-ifo.refprt])
%%
    plot(ifo.offst,ifo.smres'-(ifo.ref)*ones(1,size(ifo.smres,1)))
%%    
    useref = ifo.ref; % ifo.ref     or    ifo.ref2-1
    [I,J]=find(diff((ifo.smres'-useref*ones(1,size(ifo.smres,1)))'<0));
    delcols = unique(J(diff(J)==0));
    if isempty(delcols)
        maxUseCol = size(ifo.smres,2);
    else
        maxUseCol = delcols(1)-1;
    end;
    [I,J]=find(diff((ifo.smres(:,1:maxUseCol)'-useref(1:maxUseCol)*ones(1,size(ifo.smres,1)))'<0));
    zofs = [];
    delt = [];
    for k = 1:numel(I);
        d = ifo.smres(I(k)+(0:1),J(k))-useref(J(k));
        delt(k) = diff(d);
        zofs(k) = interp1(d,ifo.offst(I(k)+(0:1)),0);
    end;
    plot(ifo.A(1:numel(I)),[ifo.offst(I)' zofs' delt'])
%%
%     Xz = [ones(numel(J),1) ifo.A(J)' ifo.A(J)'.^2 ifo.A(J)'.^3 ifo.A(J)'.^4 ifo.A(J)'.^5] ;
    Xz = [ones(numel(J),1) ifo.A(J)'.^2 ] ;
    nusel = sum(ifo.A(J)<5.5);
    thtA = Xz(1:nusel,:)\zofs(1:nusel)'
    plot(ifo.A(J),zofs(1:numel(J))'-Xz*thtA)
%%
    correctedVal = [];
    for k = 1:numel(ifo.A);
%         offst = max(min( 0.39340331817967 + 0.00015345716910.*ifo.A(k).^2 , 1),ifo.A(k)-9);
%         offst = max(min( 0.19705524497912 + 0.00001894603555.*ifo.A(k).^2 , 1),ifo.A(k)-9);
        offst = max(min( 0.19705516068586 + 0.00001895811306.*ifo.A(k).^2 , 1),ifo.A(k)-9);

%                          0.39340322346321   0.00015346693919
        correctedVal(k) = interp1(ifo.offst,ifo.smres(:,k),offst);
    end;
    plot(ifo.A,[correctedVal'-(ifo.ref2-1) correctedVal'-ifo.ref])
%%
end;